#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution{
    public:
    //MyAnswer-->比官方好 7ms
    int ans1(vector<int>& num){
        int length = num.size();
        int p = 0;
        while(p < length-2){
            if(num[p] == num[p+1] && num[p] == num[p+2]){
                int temp = num[p+2];
                for(int i = p+2; i != length-1; i++){
                    num[i] = num[i+1];
                }
                num.pop_back();
                length--;  
            }
            else{
                p++;
            }
        }
        return num.size();
    }
    //双指针-->官方 9ms
    int ans2(vector<int>& num){
        int length = num.size();
        int p1 = 0;
        if(length > 2){
            for(int i = 2; i != length; i++){
                if(num[p1] != num[i]){
                    num[p1+2] = num[i];
                    p1++;
                }
            }
            return p1 + 2;
        }
        else{
            return length;
        }   
    }

    int ans3(vector<int>& num){
        int number = 1;
        int flag = 0;
        for(int p1 = 0, p2 = 1; p2 != num.size(); p2++){
            if(num[p1] == num[p2]){
                flag++;
                if(flag >= 2){
                    continue;
                }
                number++;
            }
            else{
                p1 = p2;
                flag = 0;
                number++;
            }
        }
        return number;
    }

    void show(vector<int> &num){
        int length = num.size();
        cout << "[" << ends;
        for(int i = 0; i != length-1; i++){
            cout << num[i] << "," << ends;
        }
        cout << num[length-1] << "]" << endl;
    }
};

void test1(){
    vector<int> num = {1, 1, 1, 2, 2, 3};

    Solution s;
    // int ret = s.ans1(num);
    //int ret = s.ans2(num);
    int ret = s.ans3(num);
    cout << ret << endl;
    s.show(num);
}

void test2(){
    vector<int> num = {0, 0, 1, 1, 1, 1, 2, 3, 3};

    Solution s;
    // int ret = s.ans1(num);
    //int ret = s.ans2(num);
    int ret = s.ans3(num);
    cout << ret << endl;
    s.show(num);
}
int main(void){
    test1();
    test2();

    return 0;
}